<template>
	<view>
		<view class="border-bottom border-light-secondary animate__animated animate__fast animate__fadeIn" style="margin-top: 100rpx;">
			<text class="iconfont icon-haoyou" style="font-size: 50rpx;padding-left: 20rpx;" @click="haoyou"></text>
			<text style="padding-left: 260rpx; padding-right: 220rpx;">消息列表</text>
			<text class="iconfont icon-caidan"style="font-size: 50rpx;" @click="caidan"></text>
		</view>
		
		<!-- 消息列表 -->
		<template v-if=" newsList.length>0">
		<block v-for="(item,index) in newsList " :key="index">
			<msg-list :item="item" :index="index"></msg-list>
		</block>
		</template>
		<template v-else>
			<no-thing></no-thing>
		</template>
		<!-- 弹出层 -->
		<uni-popup ref="popup" type="bottom" >
			<view class="flex align-cente justify-center font-md border-bottom py-2" hover-class="bg-light" @click="popupEvent('friend')">
				<text class="iconfont icon-sousuo mr-2">添加好友</text>
			</view>
			<view class="flex align-cente justify-center py-2 font-md border-bottom " hover-class="bg-light" @click="popupEvent('clear')">
				<text class="iconfont icon-shanchu mr-2">清除记录</text>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	const demo=[{
					avatar:"/static/tabber/default.jpg",
					username:"昵称",
					update_time:1570718427,
					data:"内容内容内容内容内容内容内容内容内容内容内容内容",
					nored:20
					
				},
					{
						avatar:"/static/tabber/default.jpg",
						username:"昵称",
						update_time:1570718427,
						data:"内容内容内容内容内容内容内容内容内容内容内容内容",
						nored:20
						
					},
					
						{
							avatar:"/static/tabber/default.jpg",
							username:"昵称",
							update_time:1570718427,
							data:"内容内容内容内容内容内容内容内容内容内容内容内容",
							nored:20
							
						}
					
				];
	import uniBadge from '@/components/uni-ui/uni-badge/uni-badge.vue'
	import msgList from '@/components/msg/msg-list.vue'
	import $T from '@/common/time.js'
	import uniPopup from '@/components/uni-ui/uni-popup/uni-popup.vue'
	import noThing from '@/components/common/no-thing.vue'
	export default {
		components:{
			uniBadge,
			msgList,
			noThing ,
			uniPopup 
		},
		data() {
			return {
				list:[],
				demo:[],
				newsList:[]
			}
		},
		//过滤器
		 filters:{
			 formatTime(value){
				 return $T.gettime(value);
			 }
		 },
		 onShow() {
		 	this.getUser()
		 },
		 //页面加载
		 onLoad(){
			 this.list=demo
		 },
		 //监听下拉刷新
		 onPullDownRefresh(){   
			 this.refresh()
		 },
		methods: {
			//获取数据
			async getUser() {
							var arr=[]
							const res = await uniCloud.callFunction({
								name: "friend",
								data: {
									action: 'getOne',
									id:this.$store.state.loginsStatus
								}
							})
							this.friend=res.result.data[0].friend
							console.log(this.friend)
					for(let j=0;j<this.friend.length;j++){
					console.log(111111112345)
					console.log(this.friend[j])
					const res = await uniCloud.callFunction({
						name: "userinformation",
						data: {
							action: 'getOne',
							id:this.friend[j]
						}
					})
					this.demo=res.result.data[0]
					console.log(this.demo)
					arr.push(this.demo)
				}
				this.newsList=arr
				console.log(this.newsList.length)
				},
			
			//下拉刷新
			refresh(){
				setTimeout(()=>{
					this.list=demo
					uni.stopPullDownRefresh( )
				},1000)
			},
			caidan(e){
				this.$refs.popup.open()
			},
			haoyou(e){
				uni.navigateTo({
					url:'../user-list/user-list'
				})
			},
			//弹出层点击事件
			popupEvent(e){
				switch(e){
					case 'friend':
					uni.navigateTo({
						url:'../search/search?type=user'
					})
					break;
					case 'clear':
					console.log('清除列表');
					break;
					
				}
				//关闭弹出层
				this.$refs.popup.close()
				}
			}
}

</script>

<style>

</style>
